require("../css/login.less")



document.ready(function(){

let phoneIpt=document.querySelector("#phone")
let psdIpt=document.querySelector("#psd")
let submitBtn=document.querySelector("#submitBtn")
let tips=document.querySelector(".tips")
 
submitBtn.addEventListener("click",function(){
    let phone=phoneIpt.value
    let psd=psdIpt.value

    if(!window.$utils.isphone(phone)){
     tips.textContent="手机号输入错误"
    }else if(!window.$utils.ispsd(psd)){
     tips.textContent="密码输入错误"
    }else{
     tips.textContent=""
        axios.post("http://139.9.177.51:8099/users/login",
        {
            "account":phone,
            "password":psd
        }
        )
        .then(function(res){
          let ret=res.data
          if(ret.status===0){

             window.$utils.toast("√","登录成功")
           window.setTimeout(function(){
               window.location.href="./index.html"

           },3200)
            
            
        window.localStorage.setItem("user",JSON.stringify(ret.data.user))
          }else if(ret.status===5001){
              window.$utils.toast("×","用户名或密码")
        
          }else if(ret.status===555){
              window.$utils.toast("×","用户名或密码")
           

        }
        })
        .catch(function(err){
            console.log(err);
            
        })
        
    }
})

})